package com.km.team.phsystem.service.impl;

import com.km.team.phsystem.beans.pojo.QueueInfo;
import com.km.team.phsystem.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.beans.Transient;
import java.util.List;

/**
 * @author ：Riven.
 * @description：
 * @date ：2018/12/5
 */
@Service("centralizedDateTimeSlotHandleService")
public class CentralizedDateTimeSlotHandleServiceImpl implements CentralizedDateTimeSlotHandleService {
    private final TemporaryAppointmentService temporaryAppointmentService;
    private final TimeSlotPhConfigService timeSlotPhConfigService;
    private final IQueueService iQueueService;

    @Autowired
    public CentralizedDateTimeSlotHandleServiceImpl(TemporaryAppointmentService temporaryAppointmentService,
                                                    TimeSlotPhConfigService timeSlotPhConfigService,
                                                    IQueueService iQueueService) {
        this.temporaryAppointmentService = temporaryAppointmentService;
        this.timeSlotPhConfigService = timeSlotPhConfigService;
        this.iQueueService = iQueueService;
    }

    /**
     * 业务列表增加时，统一增加
     * 日期
     * 时段
     * 日期时段
     * 临时
     *
     * @param businessId
     * @return
     */
    @Transient
    @Override
    public Boolean centralizedDeleteForBusinessId(Integer businessId) {

        //插叙需要删除的业务是否有排号，如有排号，则无法删除
        List<QueueInfo> dateForBusinessIdList = this.iQueueService.getDateForBusinessId(businessId);
        if (CollectionUtils.isEmpty(dateForBusinessIdList)) {
            //删除时段
            this.timeSlotPhConfigService.deleteForBusiness(businessId);

            //删除
            this.temporaryAppointmentService.deleteForBusinessId(businessId);
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    }

}
